<template>
	<view>
		<baseHead title="加入我们" />
		<template v-if="inviteInfo.Status==0">
			<view class="invite-desc">{{inviteInfo.InviteUserName}}邀请你加入{{inviteInfo.FullName}}，请填写以下信息</view>
			<view class="invite-form">
				<u-form labelPosition="left" :model="model" :rules="rules" ref="uForm">
					<u-form-item label="姓名" prop="MebmerName" ref="MebmerName">
						<u--input v-model="model.MebmerName"></u--input>
					</u-form-item>
				</u-form>
			</view>
			<view class="invite-sure">
				<u-button type="primary" size="large" shape="square" color="#3476FE" text="确认加入" @click="submit"></u-button>
			</view>
		</template>
		<template v-else-if="inviteInfo.Status==1">
			<view class="invite-desc">你已加入该企业{{inviteInfo.FullName}}</view>
		</template>
		<template v-else>
			<view class="invite-desc">邀请已过期失效，请确认是否正确</view>
		</template>
	</view>
</template>

<script>
	import baseHead from "@/pages/component/baseHead.vue";
	export default {
		components: {
			baseHead,
		},
		data() {
			return {
				code: '',
				model: {
					MebmerName: '',
				},
				inviteInfo: {
					Status: 2
				},
				rules: {
					'MebmerName': {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
				}
			}
		},
		onLoad(option) {
			if (option && option.code) {
				this.code = option.code;
				this.$http.core.get_joinCorp({
					code: this.code
				}).then(res => {
					if (res.Success) {
						this.inviteInfo = res.Result;
					}
				})
			}
		},
		methods: {
			submit() {
				this.$refs.uForm.validate().then(res => {
					this.$http.core.joinCorp({
						Code: this.code,
						MebmerName: this.model.MebmerName,
					}).then(res => {
						if (res.Success) {
							uni.$u.toast('加入企业成功');
							setTimeout(() => {
								uni.navigateBack()
							}, 500)
						}
					})
				}).catch(errors => {
					uni.$u.toast('请填写正确的信息')
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #F7F9FB;
	}

	.invite-desc {
		margin-top: 60rpx;
		padding: 0rpx 60rpx;
		text-align: center;
		font-size: 32rpx;
		font-weight: 500;
		line-height: 40rpx;
		color: #030303;
	}

	.invite-form {
		padding: 40rpx 100rpx;
	}

	.invite-sure {
		margin-top: 100rpx;
		padding: 0rpx 100rpx;
	}
</style>